<?php
require_once( 'db_config.inc.php' );
require_once( 'DB.php' );

$db = & DAO::CreateInstance();

//B2C part
//cleanup first 
$sql = "truncate table recommend_b2cshop";
$db->Query( $sql );
$sql = "select id from shop_info where plat_id>=100 order by review_count desc limit 0,4";
$result = $db->GetCol( $sql );
$sql = "insert into recommend_b2cshop ( user_id, b2cshops) values (0, '".implode(",", $result)."')";
$db->Query( $sql );

//C2C part
//cleanup first 
$sql = "truncate table recommend_c2cshop";
$db->Query( $sql );
$sql = "select id from shop_info where plat_id<100 order by review_count desc limit 0,4";
$result = $db->GetCol( $sql );
$sql = "insert into recommend_c2cshop ( user_id, c2cshops) values (0, '".implode(",", $result)."')";
$db->Query( $sql );

//product part
//cleanup first 
$sql = "truncate table recommend_product";
$db->Query( $sql );
$sql = "select id from product_info order by review_count desc limit 0,4";
$result = $db->GetCol( $sql );
$sql = "insert into recommend_product ( user_id, products) values (0, '".implode(",", $result)."')";
$db->Query( $sql );

//review part
//cleanup first 
$sql = "truncate table recommend_review";
$db->Query( $sql );
$sql = "select id from review order by view_count desc limit 0,4";
$result = $db->GetCol( $sql );
$sql = "insert into recommend_review ( user_id, review_id) values (0, '".implode(",", $result)."')";
$db->Query( $sql );

//At last, disconnect database
$db->Disconnect();
?>
